package principle.prisegregation;

/**
 * 这个不满足接口隔离原则，
 * 类A通过接口Interface1依赖类B，
 * 类C通过接口Interface1依赖类D，
 * 如果接口Interface1对于类A和类C来说不是最小接口，
 * 那么类B和类D必须去实现他们不需要的方法。
 *
 * @author Fengdong.Duan
 * @create 2023/11/7 10:55
 */
public class Segregation1 {
    public static void main(String[] args) {
        A a = new A();
        C c = new C();

        a.use(new B());
        c.use(new D());

    }
}

interface Interface1 {
    void operation1();

    void operation2();

    void operation3();

    void operation4();

    void operation5();
}

class B implements Interface1 {

    @Override
    public void operation1() {
        System.out.println("类B实现了operation1");
    }

    @Override
    public void operation2() {
        System.out.println("类B实现了operation2");
    }

    @Override
    public void operation3() {
        System.out.println("类B实现了operation3");
    }

    @Override
    public void operation4() {
        System.out.println("类B实现了operation4");
    }

    @Override
    public void operation5() {
        System.out.println("类B实现了operation5");
    }
}

class D implements Interface1 {

    @Override
    public void operation1() {
        System.out.println("类D实现了operation1");
    }

    @Override
    public void operation2() {
        System.out.println("类D实现了operation2");
    }

    @Override
    public void operation3() {
        System.out.println("类D实现了operation3");
    }

    @Override
    public void operation4() {
        System.out.println("类D实现了operation4");
    }

    @Override
    public void operation5() {
        System.out.println("类D实现了operation5");
    }
}

class A {
    public void use(Interface1 interface1) {
        interface1.operation1();
        interface1.operation2();
        interface1.operation3();
    }
}

class C {
    public void use(Interface1 interface1) {
        interface1.operation1();
        interface1.operation4();
        interface1.operation5();
    }
}
